;;; early-init.el --- Emacs pre-initialization config -*- lexical-binding: t -*-
;;; Commentary:

;;; Code:

;; 启动加速
;; From: https://github.com/doomemacs/doomemacs/blob/267aa3d78850dec1718fa0d3baeb153677618691/early-init.el#L32
(if noninteractive  ; in CLI sessions
    (setq gc-cons-threshold 134217728  ; 128mb
          gc-cons-percentage 1.0)
  (setq gc-cons-threshold most-positive-fixnum))
(setq read-process-output-max (* 4 1024 1024)) ; 子进程读取的最大字节数

;; 配置内置的 package 包管理器
(setq file-name-handler-alist nil)     ; 避免加载远程文件的时候分析文件
(setq package-enable-at-startup nil)   ; Disable package.el
(setq package-quickstart nil)          ; 不从包缓存中加载
(setq native-comp-jit-compilation nil) ; 禁用即时编译

;; 定义所需文件夹
(setq default-directory (expand-file-name "~/"))
(setq user-emacs-directory (expand-file-name "~/.emacs.d/"))
(setq no-littering-etc-directory
      (expand-file-name (convert-standard-filename "etc/") user-emacs-directory))
(setq no-littering-var-directory
      (expand-file-name (convert-standard-filename "var/") user-emacs-directory))
(setq org-directory (expand-file-name "~/org/"))
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)) ; 自定义配置保存入单独文件
(when (file-exists-p custom-file)
  (load custom-file)) ; 加载 custom.el 文件内的自定义配置

;; 禁止展示菜单栏、工具栏和纵向滚动条
(push '(menu-bar-lines       . 0) default-frame-alist)
(push '(tool-bar-lines       . 0) default-frame-alist)
(push '(vertical-scroll-bars . 0) default-frame-alist)

;; 禁止自动缩放窗口先
(setq frame-inhibit-implied-resize t)

;; 禁止菜单栏、工具栏、鼠标悬停弹窗、滚动条模式，禁止启动屏幕和文件对话框
(menu-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(scroll-bar-mode -1)
(setq use-dialog-box nil)            ; 鼠标操作不使用对话框
(setq inhibit-default-init t)        ; 不加载 `default' 库
(setq inhibit-startup-screen t)      ; 不加载启动画面
(setq inhibit-startup-message t)     ; 不加载启动消息
(setq inhibit-startup-buffer-menu t) ; 不显示缓冲区列表

;; eln-cache/ 放入 var/ 下
;; Native compilation cache
(when (fboundp 'startup-redirect-eln-cache)
  (startup-redirect-eln-cache
   (convert-standard-filename
    (expand-file-name  "var/eln-cache/" user-emacs-directory))))

;; Coding System
(setq system-time-locale "C")
(set-default-coding-systems 'utf-8)
(set-language-environment "UTF-8")

;; Special configs for MS-Windows
(when (eq system-type 'windows-nt)
  (set-default 'process-coding-system-alist
               '(("[rR][gG]" . (utf-8 . gbk-dos))
                 ("[fF][dD]" . (utf-8 . gbk-dos))
                 ("[pP][lL][iI][nN][kK]" .(gbk-dos . gbk-dos))
	         ("[cC][mM][dD][pP][rR][oO][xX][yY]" . (gbk-dos . gbk-dos)))))
(when (and (eq system-type 'windows-nt)
           (boundp 'w32-get-true-file-attributes))
  (setq w32-get-true-file-attributes nil
        w32-pipe-read-delay 0
        w32-pipe-buffer-size (* 64 1024)))

;; Local Variables:
;; no-byte-compile: t
;; no-native-compile: t
;; no-update-autoloads: t
;; End:

;;; early-init.el ends here
